# -*- coding: UTF-8 -*-
import threading

'''
如果想在线程执行的多个方法之间传递参数
'''

# 创建全局ThreadLocal对象: 每一个线程的副本拷贝 相当于一个字典 {'线程内存地址':{'定义的key':定义的值}}
thread_local = threading.local()


def process_student():
    # 获取当前线程关联的student:
    std = thread_local.student
    print('Hello, %s (in %s)' % (std, threading.current_thread().name))


def process_thread(name):
    # 绑定ThreadLocal的student:
    thread_local.student = name
    process_student()


t1 = threading.Thread(target=process_thread, args=('a',), name='Thread-A')
t2 = threading.Thread(target=process_thread, args=('b',), name='Thread-B')
t1.start()
t2.start()
t1.join()
t2.join()
